#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project : AutomaticTestProgram 
@File    : work_wechat.py
@IDE     : PyCharm 
@Author  : Mario
@Date    : 2022/11/29 12:02 
@Describe: 企业微信消息通知
"""
import requests
from utils.time.time_control import get_now_time


def send_work_wechat_message(port_url, port_name, payload, message, status_code, trace_id):
    """企业微信推送群聊机器人消息"""
    # 探鱼消息推送地址: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=309127ed-941f-41ac-a590-519f86cf721d
    # 甘棠消息推送地址: https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=aaa95703-4b94-4f5b-b197-7e7e6519e307
    url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=aaa95703-4b94-4f5b-b197-7e7e6519e307'
    now_time = get_now_time()
    data = {
        "msgtype": "markdown",
        "markdown": {
            "content": '''<font color=\"info\">{}</font>接口发现报错,请相关同事注意~
                    >报错时间:<font color=\"warning\">**{}**</font> 
                    >接口名称:<font color=\"warning\">**{}**</font> 
                    >请求参数:<font color=\"warning\">`{}`</font> 
                    >接口响应:<font color=\"warning\">**{}**</font> 
                    >Http状态码:<font color=\"warning\">**{}**</font> 
                    >TraceId:<font color=\"warning\">`{}`</font>'''.format(port_url, now_time, port_name,
                                                                           payload, message,
                                                                           status_code, trace_id)
        }
    }
    requests.post(url, json=data)
